---
sidebar_position: 4
tags: [env, .env, dotenv]
---

import { History } from '@site/src/components/History';

# ⚙️ env

Reads an environment file and sets the environment variables.

<History
  records={[
    {
      version: '2.5.0',
      changes: [
        <>
          <strong>CLI:</strong> deprecate <code>--env-File</code> in order to{' '}
          <code>--envFile</code>.
        </>,
      ],
    },
  ]}
/>

## CLI

Loading the `.env` by default:

```sh
npx poku --envFile
```

Loading a custom `.env`:

```sh
npx poku --envFile='path/to/my/.env'
```

<hr />

## API

> You can set a `.env` file directly in a specif test or by using it globally.

Loading the `.env` by default:

```ts
import { envFile } from 'poku';

await envFile();
```

Loading a custom `.env`:

```ts
import { envFile, poku } from 'poku';

await envFile('path/to/my/.env');

await poku('./');
```

<hr />

:::note
It's not possible to retrieve files from directories above the current process, e.g. `../.env`.
:::

<hr />

:::danger
**Poku** is made entirely for testing purposes, please don't use this functionality outside of testing.
:::

<hr />

## Real Examples

- `.env.test`

```sh
HOST='localhost'
PORT='8080'
```

Then, in a test file, you can use it as:

```js
import { assert } from 'poku';

const host = process.env.HOST;
const port = process.env.PORT;

// Your tests come here
```

Then, run your tests

```sh
npx poku --envFile='.env.test'
```
